'
' DNN Content Builder - sourceforge.net/projects/dnncb
' Copyright (c) 2004-2007
' by Emerson Lopes (emersonlopes@gmail.com)
'
' Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
' documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
' the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
' to permit persons to whom the Software is furnished to do so, subject to the following conditions:
'
' The above copyright notice and this permission notice shall be included in all copies or substantial portions 
' of the Software.
'
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
' TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
' THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
' CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
' DEALINGS IN THE SOFTWARE.
'

Imports System.Web.UI
Imports System.Xml


Public Class TextBoxIIDef
    Inherits System.Web.UI.UserControl
    Implements DNNContentBuilder.IFormletDef

    Public Const resource As String = "~/DesktopModules/DNNContentBuilder/App_LocalResources/TextBoxIIDef"

    Protected xmlDoc As New XmlDocument


#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents txtMaxLength As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtRegExp As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtStyle As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtSize As System.Web.UI.WebControls.TextBox

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
    End Sub

    Public Sub GetXml(ByVal XML As String) Implements DNNContentBuilder.IFormletDef.GetXml
        Dim tempXml As New XmlDocument

        Dim tempNode As XmlNode

        tempXml.LoadXml(XML)

        tempNode = tempXml.SelectSingleNode("//Style")
        tempNode.InnerText = Me.txtStyle.Text

        tempNode = tempXml.SelectSingleNode("//MaxLength")
        tempNode.InnerText = txtMaxLength.Text

        tempNode = tempXml.SelectSingleNode("//Size")
        tempNode.InnerText = txtSize.Text

        tempNode = tempXml.SelectSingleNode("//RegExp")
        tempNode.InnerText = txtRegExp.Text

        tempNode = tempXml.SelectSingleNode("//UniqueId")

        Dim lastButton As ImageButton

        lastButton = Page.FindControl(tempNode.InnerText)

        lastButton.CommandArgument = tempXml.OuterXml
    End Sub

    Public Sub SetXml(ByVal parXML As String) Implements DNNContentBuilder.IFormletDef.SetXml
        Dim xml As XmlDocument = New XmlDocument

        Dim tempNode As XmlNode

        xml.LoadXml(parXML)

        tempNode = xml.SelectSingleNode("//MaxLength")

        If (tempNode Is Nothing) Then

            Dim tempXml As New XmlDocument

            tempXml.LoadXml(parXML)

            tempNode = tempXml.SelectSingleNode("//ExtendedProperties")

            Dim epXml As New XmlDocument

            epXml.Load(System.Web.HttpContext.Current.Server.MapPath("DesktopModules\\DNNContentBuilder\\UserControls\\FieldControls\\TextBoxII\\TextBoxIIDef.xml"))

            tempNode.InnerXml = epXml.InnerXml

            xmlDoc.LoadXml(tempXml.OuterXml)
        Else
            xmlDoc.LoadXml(parXML)
        End If

        tempNode = xmlDoc.SelectSingleNode("//Style")
        txtStyle.Text = tempNode.InnerText

        tempNode = xmlDoc.SelectSingleNode("//MaxLength")
        txtMaxLength.Text = tempNode.InnerText

        tempNode = xmlDoc.SelectSingleNode("//Size")
        txtSize.Text = tempNode.InnerText

        tempNode = xmlDoc.SelectSingleNode("//RegExp")
        txtRegExp.Text = tempNode.InnerText

        Dim lastButton As ImageButton

        lastButton = Page.FindControl(CType(Session("lastButton"), String))
        lastButton.CommandArgument = xmlDoc.OuterXml

    End Sub
End Class
